package com.example.denist;

import com.example.denist.action.MyGallery;
import com.example.denist.action.OptoinInit;
import com.example.denist.adapter.ImageAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Gallery;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class MainActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		OptoinInit optoinInit = new OptoinInit(this);
		optoinInit.init();
		
		final RadioButton[] items = {
				(RadioButton)findViewById(R.id.item1),
				(RadioButton)findViewById(R.id.item2),
				(RadioButton)findViewById(R.id.item3),
				(RadioButton)findViewById(R.id.item4),
		};
		
		final MyGallery g = (MyGallery)findViewById(R.id.gallery);
		ImageAdapter imageAdapter = new ImageAdapter(this);
		g.setAdapter(imageAdapter);
		g.setFocusable(true);
		g.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				int i = arg2 % items.length;
				switch (i) {
				case 0:
					items[i].setChecked(true);
					break;
				case 1:
					items[i].setChecked(true);
					break;
				case 2:
					items[i].setChecked(true);
					break;
				case 3:
					items[i].setChecked(true);
					break;
				default:
					break;
				}
				
			}
			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				
			}
			
		});
		
		
		RadioGroup radioGroup = 
				(RadioGroup)findViewById(R.id.radioGroup);
		radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.item1:
					g.setSelection(0);
					break;
				case R.id.item2:
					g.setSelection(1);
					break;
				case R.id.item3:
					g.setSelection(2);
					break;
				case R.id.item4:
					g.setSelection(3);
					break;
				default:
					break;
				}
			}
		});
	}

	
	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}
